<?php

namespace App\Console\Commands;

use App\Models\User;
use Illuminate\Console\Command;

class GenerateToken extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'chat_api_bak:generate-token';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '快速创建长期有效Token令牌';


    public function __construct() {
        parent::__construct();
    }


    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $userId = $this->ask('请输入用户id');

        $user = User::find($userId);

        if (!isset($user)) return $this->error('用户不存在');

        $ttl = 365 * 24 * 60;

        return $this->info(auth('api')->setTTL($ttl)->login($user));
    }
}
